/*
 * MainMenu_Controller.java
 * Final Project Example
 * Created on Oct 8, 2014, 10:58:26 PM
 * by Fairul Filza with Team FA_PemrogrammanLanjut
 */

package Controllers;

// <editor-fold defaultstate="collapsed" desc="Import Code">
import Interfaces.ControllersProcess_Interface;
import static Interfaces.ControllersProcess_Interface.FILE_EXIT;
import static Interfaces.ControllersProcess_Interface.HELP_ABOUT;
import static Interfaces.ControllersProcess_Interface.TOOLS_UNUSED;
import Models.Dvds_Model;
import Models.SalesDetail_Model;
import Models.Sales_Model;

import Views.MasterCd_EditView;
import Views.Transaction_EditView;
import Views.Transaction_ListView;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;


import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import static java.awt.print.Printable.NO_SUCH_PAGE;
import static java.awt.print.Printable.PAGE_EXISTS;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
// </editor-fold>

/** @author PemrogrammanLanjut_LABIV_TI_05~09 */
public class Transaction_Controller implements ControllersProcess_Interface, Printable {
    private Transaction_EditView EditView;
    private Transaction_ListView ListView;
    private Calendar CurrentDate;
    private SimpleDateFormat DateForm;
    private int flag;
    private int banyak;
    private long total;
    private boolean status;


    // <editor-fold defaultstate="collapsed" desc="Constructor Code">
    public Transaction_Controller(Transaction_EditView EditView) {
        this.EditView = EditView;
        
    }
    public Transaction_Controller(Transaction_ListView ListView) {
        this.ListView = ListView;
        fillCboYear(ListView.getCboYear(), "");
        fillCboMonth(ListView.getCboMonth(), "");
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Getter and Setter Code">
    public Transaction_EditView getEditView() {
        return EditView;
    }

    public void setEditView(Transaction_EditView EditView) {
        this.EditView = EditView;
    }
    
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Method Code">
    private void tblData_componentShown() {
        Sales_Model Model;
        DefaultTableModel Record;
        String[] Header;
        int[] wCol;

        Header = new String[] {"CODE", "DATE", "QTY", "TOTAL"};
        Model = new Sales_Model();
        Model.showDataSet();
        Record = new DefaultTableModel(Model.getDataRecord(), Header){
            @Override
            public boolean isCellEditable(int row, int column) {
            //Only the third column
            return false;
        }
        };
        wCol = new int[] {0, 150, 100, 200};
        ListView.getTblData().setModel(Record);
        ListView.getBtnDelete().setIcon(new ImageIcon(getClass().getResource("/Images/delete3.png")));
        ListView.getBtnDelete().setEnabled(false);

        initColumnRecord(ListView.getTblData(), wCol);
    }
    private void tblData_keyPressed() {
        String Code = ListView.getTblData().getValueAt(ListView.getTblData().getSelectedRow(), 0).toString();
        tblDetail_componentShown(ListView.getTblDetail(), Code);
        System.out.println(Code);
        ListView.getLblCode().setText(Code);
        ListView.getBtnDelete().setIcon(new ImageIcon(getClass().getResource("/Images/delete.png")));
        ListView.getBtnDelete().setEnabled(true);
    }
    private void btnMenu_mouseClick(int code) {
        switch(code) {
            case FILE_EXIT:
                System.exit(0);
                break;
            case TOOLS_UNUSED:
                break;
            case HELP_ABOUT:
                break;
        }
    }


    private void frmMain_windowClosing() {
        if(JOptionPane.showConfirmDialog(null, "Are You Sure?", "Warning",
                JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
            System.exit(0);
        }
    }

    private void txtCdId_keyPressed(int flag) {
        switch (flag) {
            case 0:
                if(EditView.getTxtCdId().getText().matches("")) {
                    System.out.println("tidak ketemu");
                } else {
                    dvdSelected(EditView.getTxtCdId().getText());
                }
                break;
            case 1:
                int total1 = Integer.parseInt(EditView.getLblTotal().getText().toString());
                int cash = Integer.parseInt(EditView.getTxtCash().getText().toString());
                if(total>cash){
                    JOptionPane.showMessageDialog(EditView, "Cash is not enought");
                }else{
                    EditView.getTxtChange().setText(String.valueOf(cash-total));
                }
                
                break;
        }
    }
    private void btnRefresh_mouseClick() {
        tblData_componentShown();
        ListView.getLblCode().setText("");
        ListView.getTblDetail().setModel(new DefaultTableModel());
    }
    private void btnDelete_mouseClick() {
        Sales_Model Model;

        Model = new Sales_Model(ListView.getLblCode().getText());
        if (JOptionPane.showConfirmDialog(null, "Transact will be Removed!", "Caution",
            JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
            if(Model.subDataValue()) {
                tblData_componentShown();
                btnRefresh_mouseClick();
            }
        }
    }
    private void btnCheck_mouseClick() {
        Sales_Model Model;
        if(EditView.getTxtCode().getText().matches("")) {
            JOptionPane.showMessageDialog(EditView, "Text Code is Empty");
        } else if(EditView.getTxtCash().getText().matches("")){
            JOptionPane.showMessageDialog(EditView, "Text Cash is Empty");
            EditView.getTxtCash().requestFocus();
        } else if(EditView.getTxtChange().getText().matches("")){
            txtCdId_keyPressed(1);
            JOptionPane.showMessageDialog(EditView, "Text Change is Empty");
            
        }
        else {
            Model = new Sales_Model(EditView.getTxtCode().getText(), pickDateDbFormat(), Long.parseLong(EditView.getLblTotal().getText()));
            if(Model.editDataValue()) {
//                print(null, null, flag)
                PrinterJob job = PrinterJob.getPrinterJob(); //Get the printer's job list
                    job.setPrintable(this); //We print with this class (btnPrintAction, which implements Printable)
                    if (job.printDialog() == true) { //If we clicked OK in the print dialog
			try {job.print();} catch (PrinterException ex){
                            //It did not work (PrinterException thrown), so add any error handling routines.
			}
                }
                total = 0;
                frmEditor_formShown();
                tblDetail_componentShown(EditView.getTblDetail(), EditView.getTxtCdId().getText());
                status = true;
            }
        }
    }
    public int print(Graphics gx, PageFormat pf, int page) throws PrinterException {
	SalesDetail_Model Model;
        if (page>0){return NO_SUCH_PAGE;} //Only one page
	Graphics2D g = (Graphics2D)gx; //Cast to Graphics2D object
	g.translate(pf.getImageableX(), pf.getImageableY()); //Match origins to imageable area
        Font FontStyle = new Font("Tahoma", 1, 16);
        g.setFont(FontStyle);
        g.drawString("PRO CONTRA", 100, 100);
        
        FontStyle = new Font("Tahoma", 1, 14);
        g.setFont(FontStyle);
        g.drawString("Pusat Penjualan CD Terlengkap", 40, 113);
        
        FontStyle = new Font("Tahoma", 1, 12);
        g.setFont(FontStyle);
        g.drawString("TransId = " + EditView.getTxtCode().getText(), 15, 130);
        g.drawString(pickDateDbFormat(), 200, 130);
        
        FontStyle = new Font("Tahoma", 1, 11);
        g.setFont(FontStyle);
        g.drawString("Title", 10, 140);
        g.drawString("Price", 120, 140);
        g.drawString("Qty", 170, 140);
        g.drawString("Amount", 220, 140);
        Model = new SalesDetail_Model(EditView.getTxtCode().getText());
        Model.showDataSet();
        FontStyle = new Font("Tahoma", 1, 10);
        g.setFont(FontStyle);
        String[][] result = Model.getDataRecord();
        for(int i=0; i<result.length; i++){
            g.drawString(result[i][2], 10, 150+i*10);
            g.drawString(result[i][3], 120, 150+i*10);
            g.drawString(result[i][4], 170, 150+i*10);
            g.drawString(result[i][5], 220, 150+i*10);
        }
        
        FontStyle = new Font("Tahoma", 1, 12);
        g.setFont(FontStyle);
        g.drawString("Total", 130, 150 + (result.length+1)*10);
        g.drawString(EditView.getLblTotal().getText(), 220, 150 + (result.length+1)*10);
        g.drawString("Payment", 130, 150 + (result.length+2)*10);
        g.drawString(EditView.getTxtCash().getText(), 220, 150 + (result.length+2)*10);
        g.drawString("Change", 130, 150 + (result.length+3)*10);
        g.drawString(EditView.getTxtChange().getText(), 220, 150 + (result.length+3)*10);
//	g.drawString ("Hello world", 100, 100); //Print Hello World at offset (100, 100)
	return PAGE_EXISTS; //Page exists (offsets start at zero!)
    }
    private void frmEditor_formShown() {
        Sales_Model Model;

        Model = new Sales_Model();
        resetText();
        EditView.getTxtCode().setText(Model.genIdDataValue());
        EditView.getTxtCdId().requestFocus();
    }
    

    
    private void resetText() {
        EditView.getTxtCode().setText("");
        EditView.setNum("");
        EditView.getTxtCdId().setText("");
        EditView.getTxtTitle().setText("");
        EditView.getTxtStock().setText("");
        EditView.getTxtPrice().setText("");
        EditView.getTxtTotal().setText("");
        EditView.getTxtBanyak().setText("");
        EditView.getLblTotal().setText(String.valueOf(total));
        EditView.getTxtCash().setText("");
        EditView.getTxtChange().setText("");
        EditView.getBtnEdit().setIcon(new ImageIcon(getClass().getResource("/Images/edit3.png")));
        EditView.getBtnEdit().setEnabled(false);
        EditView.getBtnDelete().setIcon(new ImageIcon(getClass().getResource("/Images/delete3.png")));
        EditView.getBtnDelete().setEnabled(false);

        EditView.getBtnOk().setVisible(false);
        EditView.getBtnOk().setEnabled(false);
        EditView.getBtnCancel().setVisible(false);
        EditView.getBtnCancel().setEnabled(false);
    }
    
    private void tblDetail_keyPressed(int n) {
        if(n == 0){
        Sales_Model Model;
        SalesDetail_Model Mode2;
        Dvds_Model Mode3;
        String Qty, DvdId;
        int stock;

        if (JOptionPane.showConfirmDialog(null, "Transact will be Removed!", "Caution",
            JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
            DvdId = EditView.getTblDetail().getValueAt(EditView.getTblDetail().getSelectedRow(), 1).toString();
            Qty = EditView.getTblDetail().getValueAt(EditView.getTblDetail().getSelectedRow(), 4).toString();
            dvdSelected(DvdId);
            EditView.getTxtBanyak().setText(Qty);
            txtQty_keyReleased();
            Mode2 = new SalesDetail_Model(Long.parseLong(EditView.getTblDetail().getValueAt(EditView.getTblDetail().getSelectedRow(), 0).toString()));
            if(Mode2.subDataValue()) {
                stock = Integer.parseInt(EditView.getTxtStock().getText()) + Integer.parseInt(Qty);
                //stock = Integer.parseInt(Qty);
                Mode3 = new Dvds_Model(DvdId, stock);
                Mode3.editBookStock();
                Model = new Sales_Model(EditView.getTxtCode().getText(), pickDateDbFormat(), total);
                
                tblDetail_componentShown(EditView.getTblDetail(), EditView.getTxtCode().getText());
                total = Long.parseLong(Model.showGrandTotal());
                resetTransactText();
                EditView.getLblTotal().setText(String.valueOf(total));
            }
        }
        }else{
            EditView.setNum(EditView.getTblDetail().getValueAt(EditView.getTblDetail().getSelectedRow(), 0).toString());
            banyak = Integer.parseInt(EditView.getTblDetail().getValueAt(EditView.getTblDetail().getSelectedRow(), 4).toString());
            dvdSelected(EditView.getTblDetail().getValueAt(EditView.getTblDetail().getSelectedRow(), 1).toString());
        }
    }
    
    private void dvdSelected(String Code) {
        Dvds_Model Model;

        if(!Code.matches("")) {
            try {
                Model = new Dvds_Model();
                Model.showSelectedDataSet(Code, "DvdId");
                
                EditView.getTxtCdId().setText(Model.getDvdId());
                EditView.getTxtTitle().setText(Model.getTitle());
                EditView.getTxtPrice().setText(String.valueOf(Model.getPrice()));
                EditView.getTxtStock().setText(String.valueOf(Model.getStock()));
                
                EditView.getBtnAdd().setVisible(true);
                EditView.getTxtBanyak().requestFocus();
            } catch(Exception ex) {
                System.out.println("[ERROR] - Sales_Controller.bookSelected at " + ex.getMessage());
            }
        }
    }

    private void tblDetail_mouseReleased() {
        EditView.getBtnEdit().setIcon(new ImageIcon(getClass().getResource("/Images/edit.png")));
        EditView.getBtnEdit().setEnabled(true);
        EditView.getBtnDelete().setIcon(new ImageIcon(getClass().getResource("/Images/delete.png")));
        EditView.getBtnDelete().setEnabled(true);
    }
    
    private void tblDetail_componentShown(JTable Table, String Code) {
        SalesDetail_Model Model;
        DefaultTableModel Record;
        String[] Header;
        int[] wCol;
        Header = new String[] {"NUM", "CODE", "TITLE", "PRICE", "QTY", "AMOUNT"};
        Model = new SalesDetail_Model(Code);
        Model.showDataSet();
        Record = new DefaultTableModel(Model.getDataRecord(), Header){
            @Override
            public boolean isCellEditable(int row, int column) {
            //Only the third column
            return false;
        }
        };
        wCol = new int[] {0, 150, 400, 200, 100, 200};
        Table.setModel(Record);
        initColumnRecord(Table, wCol);
    }
    
    private void initColumnRecord(JTable table, int[] wCol) {
        TableColumn col = null;
        int i = 0;
        for (i = table.getColumnCount() - 1; i > 0; i--) {
            col = table.getColumnModel().getColumn(i);
            col.setPreferredWidth(wCol[i]);
        }
    }
    private void btnListFind_mouseClick() {
        Sales_Model Model;
        DefaultTableModel Record;
        String[] Header;
        int[] wCol;

        Header = new String[] {"CODE", "DATE", "QTY", "TOTAL"};
        Model = new Sales_Model();
        Model.showFoundedDataSet(pickListDateDbFormat());
        Record = new DefaultTableModel(Model.getDataRecord(), Header);
        wCol = new int[] {0, 150, 100, 200};
        ListView.getTblData().setModel(Record);
//        ListView.getBtnDelete().setVisible(false);
        initColumnRecord(ListView.getTblData(), wCol);
    }
    private void btnSet_mouseClick() {
        Sales_Model Model;
        SalesDetail_Model Mode2;
        Dvds_Model Mode3;
        String GenerateId, StrCode;
        boolean flag;
        int endStock;

        if(isValidate()) {
            Model = new Sales_Model(EditView.getTxtCode().getText());
            Model.showSelectedDataSet(EditView.getTxtCode().getText(), "SalesId");
            StrCode = Model.getSalesId();
//            System.out.println("aaaaaaaaaaaaaaaaaaaaa : " + Model.getSalesId() + " aaaaaaaaaaaaaa : " + EditView.getTxtCdId().getText());
            Model = new Sales_Model(EditView.getTxtCode().getText(), pickDateDbFormat(), total);
            if(EditView.getTxtCode().getText().equals(StrCode)) {
                flag = Model.editDataValue();
            } else {
                flag = Model.addDataValue();
            }
            
            if(flag) {
                GenerateId = EditView.getNum().equals("") ? new SalesDetail_Model().genIdDataValue() :
                        EditView.getNum();
                Mode2 = new SalesDetail_Model(Long.parseLong(GenerateId),
                                              Integer.parseInt(EditView.getTxtBanyak().getText()),
                                              Integer.parseInt(EditView.getTxtTotal().getText()),
                                              EditView.getTxtCode().getText(),
                                              EditView.getTxtCdId().getText());
                if(EditView.getNum().equals("")){
                    endStock = Integer.parseInt(EditView.getTxtStock().getText()) - Integer.parseInt(EditView.getTxtBanyak().getText());
                
                    Mode2.addDataValue();
                }else{
                    endStock = Integer.parseInt(EditView.getTxtStock().getText()) - Integer.parseInt(EditView.getTxtBanyak().getText()) + banyak;
                
                    Mode2.editDataValue();
                }
                Mode3 = new Dvds_Model(EditView.getTxtCdId().getText(), endStock);
                Mode3.editBookStock();
                tblDetail_componentShown(EditView.getTblDetail(), EditView.getTxtCode().getText());
                total = Long.parseLong(Model.showGrandTotal());
                resetTransactText();
                EditView.getLblTotal().setText(String.valueOf(total));
                EditView.getTxtCdId().requestFocus();
                status = false;
            }
        }
    }
    private void btnCancel_mouseClick() {
        Sales_Model Model;
        SalesDetail_Model Mode2;

        if (JOptionPane.showConfirmDialog(null, "Transact will be Removed!", "Caution",
            JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
            Model = new Sales_Model(EditView.getTxtCode().getText());
            Mode2 = new SalesDetail_Model();
            if(Mode2.cancelTransact(EditView.getTxtCode().getText())) {
                Model.subDataValue();
                status = true;
                total = 0;
                frmEditor_formShown();
                tblDetail_componentShown(EditView.getTblDetail(), EditView.getTxtCode().getText());
                EditView.getBtnOk().setVisible(false);
                EditView.getBtnOk().setEnabled(false);
                EditView.getBtnCancel().setVisible(false);
                EditView.getBtnCancel().setEnabled(false);
            }
        }
    }
    private boolean isValidate() {
        boolean flag;

        flag = false;
        if(EditView.getTxtCdId().getText().matches("")) {
            JOptionPane.showMessageDialog(EditView, "Code is Empty");
            EditView.getTxtCdId().requestFocus();
            flag = false;
        } else if(EditView.getTxtCdId().getText().matches("")) {
            JOptionPane.showMessageDialog(EditView, "Isbn is Empty");
            EditView.getTxtCdId().requestFocus();
            flag = false;
        } else if(EditView.getTxtBanyak().getText().matches("")) {
            JOptionPane.showMessageDialog(EditView, "Qty is Empty");
            EditView.getTxtBanyak().requestFocus();
            flag = false;
        } else if(Integer.parseInt(EditView.getTxtBanyak().getText()) < 1 ) {
            JOptionPane.showMessageDialog(EditView, "Qty Still 0");
            EditView.getTxtBanyak().requestFocus();
            flag = false;
        } else if(Integer.parseInt(EditView.getTxtBanyak().getText()) > Integer.parseInt(EditView.getTxtStock().getText())) {
            JOptionPane.showMessageDialog(EditView, "Stock Not Enough!");
            EditView.getTxtBanyak().requestFocus();
            flag = false;
        } else {
            flag = true;
        }
        return flag;
    }
    
    private void resetTransactText() {
        EditView.setNum("");
        EditView.getTxtCdId().setText("");
        EditView.getTxtTitle().setText("");
        EditView.getTxtPrice().setText("");
        EditView.getTxtTotal().setText("");
        EditView.getTxtBanyak().setText("");

        EditView.getBtnDelete().setEnabled(false);
        EditView.getBtnEdit().setEnabled(false);
        
        EditView.getBtnOk().setVisible(true);
        EditView.getBtnOk().setEnabled(true);
        EditView.getBtnCancel().setVisible(true);
        EditView.getBtnCancel().setEnabled(true);
        EditView.getBtnAdd().setVisible(true);
    }
    private String pickListDateDbFormat() {
         String TmpDate;
         String YYYY;
         String MM;

         YYYY = ListView.getCboYear().getItemAt(ListView.getCboYear().getSelectedIndex()).toString();
         MM = ((ListView.getCboMonth().getSelectedIndex() + 1) < 10) ?
              "0" + String.valueOf(ListView.getCboMonth().getSelectedIndex() + 1) :
              String.valueOf(ListView.getCboMonth().getSelectedIndex() + 1);
         TmpDate = YYYY + "/" + MM;
         return TmpDate;
    }
    private String pickDateDbFormat() {
         String TmpDate;
         String YYYY;
         String MM;
         String DD;
         Format DateMold;
         Date CurrentDate = new Date();
         DateMold = new SimpleDateFormat("yyyy");
         YYYY = DateMold.format(CurrentDate);
         DateMold = new SimpleDateFormat("MM");
         MM = DateMold.format(CurrentDate);
         DateMold = new SimpleDateFormat("dd");
         DD = DateMold.format(CurrentDate);
         TmpDate = YYYY + "/" + MM + "/" + DD;
         return TmpDate;
    }
    
    private void txtQty_keyReleased() {
        long qty, price, amount;

        qty = (EditView.getTxtBanyak().getText().matches("")) ? 0 : Long.parseLong(EditView.getTxtBanyak().getText());
        
        price = Long.parseLong(EditView.getTxtPrice().getText());

        amount = price * qty;
        EditView.getTxtTotal().setText(String.valueOf(amount));
    }
    
    private void curDate_runtimeDate() {
        String Patern = null;

        CurrentDate = Calendar.getInstance();
        DateForm = new SimpleDateFormat("dd MMMM yyyy HH:mm");
        Patern = DateForm.format(CurrentDate.getTime());

        
    }
    private void fillCboYear(JComboBox Cbo, String DateStr) {
        Date CurrentDate = new Date();
        Format DateMold = new SimpleDateFormat("yyyy");
        String[] ListYear = null;
        int val = 0;
        int i = 0;

        val = (DateStr.matches("")) ? Integer.parseInt(DateMold.format(CurrentDate)) : Integer.parseInt(DateStr.substring(0, 4));
        ListYear = new String[20];
        for(i = 0; i < 20; i++) {
            ListYear[i] = (String.valueOf(val - i));
        }

        DefaultComboBoxModel CboModel = new DefaultComboBoxModel(ListYear);
        Cbo.setModel(CboModel);
    }

    private void fillCboMonth(JComboBox Cbo, String DateStr) {
        Date CurrentDate = new Date();
        Format DateMold = new SimpleDateFormat("MM");
        int val = 0;
        String[] ListMonth = null;


        val = (DateStr.matches("")) ? Integer.parseInt(DateMold.format(CurrentDate).toString()) : Integer.parseInt(DateStr.substring(5, 7));
        ListMonth = new String[12];
        ListMonth[0] = "Januari";
        ListMonth[1] = "Pebruari";
        ListMonth[2] = "Maret";
        ListMonth[3] = "April";
        ListMonth[4] = "Mei";
        ListMonth[5] = "Juni";
        ListMonth[6] = "Juli";
        ListMonth[7] = "Agustus";
        ListMonth[8] = "September";
        ListMonth[9] = "Oktober";
        ListMonth[10] = "Nopember";
        ListMonth[11] = "Desember";

        DefaultComboBoxModel CboModel = new DefaultComboBoxModel(ListMonth);
        Cbo.setModel(CboModel);
        Cbo.setSelectedIndex(val - 1);
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Anonymous Code">
    public ActionListener EditButton_Listener = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent Evt) {
           if(Evt.getSource().equals(EditView.getBtnAdd())) {
                btnSet_mouseClick();
            }else if(Evt.getSource().equals(EditView.getBtnOk())) {
                btnCheck_mouseClick();
            }else if(Evt.getSource().equals(EditView.getBtnEdit())){
                tblDetail_keyPressed(1);
            }else if(Evt.getSource().equals(EditView.getBtnDelete())){
                tblDetail_keyPressed(0);
            }else if(Evt.getSource().equals(EditView.getBtnCancel())){
                btnCancel_mouseClick();
            }
        }
    };

    

    public MouseAdapter EditButtonImg_Listener = new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent Evt) {
            if(Evt.getSource().equals(EditView.getBtnEdit())) {
                EditView.getBtnEdit().setIcon(new ImageIcon(getClass().getResource("/Images/edit2.png")));
            } else if(Evt.getSource().equals(EditView.getBtnDelete())) {
                EditView.getBtnDelete().setIcon(new ImageIcon(getClass().getResource("/Images/delete2.png")));
            } 
        }

        @Override
        public void mouseReleased(MouseEvent Evt) {
            if(Evt.getSource().equals(EditView.getBtnEdit())) {
                EditView.getBtnEdit().setIcon(new ImageIcon(getClass().getResource("/Images/edit.png")));
            } else if(Evt.getSource().equals(EditView.getBtnDelete())) {
                EditView.getBtnDelete().setIcon(new ImageIcon(getClass().getResource("/Images/delete.png")));
            } 
        }
    };


    
    
    public ComponentAdapter EditComponent_Listener = new ComponentAdapter() {
        @Override
        public void componentShown(ComponentEvent Evt) {
            if(Evt.getSource().equals(EditView)) {
                frmEditor_formShown();
            }
        }
    };
    public ComponentAdapter ListComponent_Listener = new ComponentAdapter() {
        @Override
        public void componentShown(ComponentEvent Evt) {
            if(Evt.getSource().equals(ListView)) {
                tblData_componentShown();
            }
        }
    };
    
    public ActionListener ListButton_Listener = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent Evt) {
            if(Evt.getSource().equals(ListView.getBtnDelete())) {
                btnDelete_mouseClick();
            } else if(Evt.getSource().equals(ListView.getBtnFind())) {
                btnListFind_mouseClick();
            }
        }
    };

    

    public MouseAdapter ListButtonImg_Listener = new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent Evt) {
            if(Evt.getSource().equals(ListView.getBtnDelete())) {
                ListView.getBtnDelete().setIcon(new ImageIcon(getClass().getResource("/Images/delete2.png")));
            }
        }

        @Override
        public void mouseReleased(MouseEvent Evt) {
            if(Evt.getSource().equals(ListView.getBtnDelete())) {
                ListView.getBtnDelete().setIcon(new ImageIcon(getClass().getResource("/Images/delete.png")));
            } 
        }
    };

    
    public ActionListener CurrentDate_ActListener = new ActionListener() {
       @Override
        public void actionPerformed(ActionEvent Evt) {
            curDate_runtimeDate();
        }
    };

    public MouseAdapter EditTable_Listener = new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent Evt) {
            if(Evt.getSource().equals(EditView.getTblDetail())) {
                tblDetail_mouseReleased();
            }
        }
    };
    
    public KeyAdapter EditKey_Listener = new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent Evt) {
            if(Evt.getSource().equals(EditView.getTxtCdId())) {
                if(Evt.getKeyCode() == KeyEvent.VK_ENTER) {
                    txtCdId_keyPressed(0);
                }
            }else if(Evt.getSource().equals(EditView.getTxtBanyak())) {
                if(Evt.getKeyCode() == KeyEvent.VK_ENTER) {
                    btnSet_mouseClick();
                }
            }else if(Evt.getSource().equals(EditView.getTxtCash())) {
                if(Evt.getKeyCode() == KeyEvent.VK_ENTER) {
                    txtCdId_keyPressed(1);
                }
            } else if(Evt.getSource().equals(EditView.getTblDetail())) {
                if(Evt.getKeyCode() == KeyEvent.VK_DELETE) {
                    tblDetail_keyPressed(0);
                }else if(Evt.getKeyCode() == KeyEvent.VK_ENTER){
                    tblDetail_keyPressed(1);
                }
            }
        }

        @Override
        public void keyReleased(KeyEvent Evt) {
            if(Evt.getSource().equals(EditView.getTxtBanyak())) {
                txtQty_keyReleased();
            }
        }
    };

    public KeyAdapter ViewKey_Listener = new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent Evt) {
            if(Evt.getSource().equals(ListView.getTblData())) {
                if(Evt.getKeyCode() == KeyEvent.VK_ENTER) {
                    tblData_keyPressed();
                } else if(Evt.getKeyCode() == KeyEvent.VK_DELETE){
                    btnDelete_mouseClick();
                } 
            }
        }
    };
    
    public ActionListener LabelAnimate_ActListener = new ActionListener() {
        int i = (-530 / 2); // Sumber Bedasarkan panjang label yang akan di gerakan

        @Override
        public void actionPerformed(ActionEvent e) {
            i++;  // Pergerakan text untuk Motion Maju

            if(i == 530) i = -530; // Jika sudah mencapai titik akhir text kembali ke awal

            // Untuk Text bekedip
            if(i % 20 == 0) {  // Untuk setiap hitungan per 10
              //  EditView.getLblContext().setSize((EditView.getLblContext().getWidth() == 0) ? 185 : 0, 32); // Kedipkan text
            }
            //EditView.getLblTitle().setLocation(i + 10, 0);  // Pergerakan Text
        }
    };
    // </editor-fold>
}
// End of Code